﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility.DBUtility;
using System.IO;
using System.Text;

namespace Jxym.wlkc2011.AdminManages
{
    public partial class sql : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                string sqlText = TextBox1.Text.Trim();

                if (sqlText != "")
                {
                    Label1.Text = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringProfile, System.Data.CommandType.Text, sqlText, null).ToString();
                }
                else
                {
                    Label1.Text = "没有可以实行的语句";
                }
            }
            catch (Exception ex)
            {
                Label1.Text = ex.Message;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                try
                {
                    string filename = DateTime.Now.ToFileTime().ToString();

                    string path = Server.MapPath("~/UpFiles/");

                    string ext = Path.GetExtension(FileUpload1.FileName);

                    string fileFullName = path + filename + ext;

                    FileUpload1.SaveAs(fileFullName);

                    Encoding encoding = Jxym.Tools.MyFile.EncodingType.GetType(fileFullName);

                    if (encoding != Encoding.UTF8)
                    {
                        Jxym.Tools.MyFile.EncodingType.EncodingChange(fileFullName);
                    }

                    TextBox1.Text = File.ReadAllText(fileFullName);

                    File.Delete(fileFullName);
                }
                catch (HttpException ex)
                {
                    Label2.Text = ex.Message;
                }
                catch (Exception ex)
                {
                    Label2.Text = ex.Message;
                }
            }
        }
    }
}